/**
 * 
 */
package com.alstudio.ui.module.image;

import java.util.HashMap;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.ui.base.BaseActivity;
import com.alstudio.view.tableview.ALTableView;
import com.alstudio.view.tableview.ViewItem;
import com.alstudio.view.tableview.ALTableView.ALTableViewClickListener;
import com.loovee.imaohu.R;

/**
 * @author alonso lee
 *
 */
public class TestImageLoader extends BaseActivity implements ALTableViewClickListener{
	
	
	private ListView test_img_list;
	
	public static final String[] IMAGES = new String[] {
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
		"http://i0.sinaimg.cn/ent/s/j/2008-04-08/U2231P28T3D1978904F326DT20080408183926.JPG",
	};

	
	/* (non-Javadoc)
	 * @see com.alstudio.ui.base.BaseActivity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setupView(this, getClass().getSimpleName());
	}
	
	/* (non-Javadoc)
	 * @see com.alstudio.ui.base.BaseActivity#setupView(android.content.Context, java.lang.String)
	 */
	@SuppressLint("UseSparseArrays")
	@Override
	protected void setupView(Context context, String name) {
		// TODO Auto-generated method stub
		super.setupView(context, name);
		setContentRes(R.layout.main_discovery_list);

//		test_img_list = (ListView) findViewById(R.id.test_img_list);
//		imageUrls = IMAGES;
//		test_img_list.setAdapter(new ItemAdapter());
//		test_img_list.setCacheColorHint(0);
//		goneView(test_img_list);
		
//		ALTableView tableView = (ALTableView) findViewById(R.id.aLTableView1);
//		
////		View v = ALLocalEnv.getLocalEnv().getGlobalLayoutInflater().inflate(R.layout.dialog_list_item, null);
////		View v2 = ALLocalEnv.getLocalEnv().getGlobalLayoutInflater().inflate(R.layout.item_list_image, null);
//		ImageView v = new ImageView(this);
//		v.setImageResource(R.drawable.alert);
//		ImageView v2 = new ImageView(this);
//		v2.setImageResource(R.drawable.alert);
//		ViewItem item = new ViewItem(v);
//		ViewItem item1 = new ViewItem(v2);
////		ViewItem item2 = new ViewItem(v);
////		ViewItem item3 = new ViewItem(v);
////		ViewItem item4 = new ViewItem(v);
//
//    	tableView.addViewItem(item);
//    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//    	tableView.addViewItem(item1);
////    	tableView.addViewItem(item2);
////    	tableView.addViewItem(item3);
////    	tableView.addViewItem(item4);
////    	
////    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
////    	tableView.addViewItem(item);
//    	
//    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//
//    	tableView.addBasicItem("Example 1 - UITableView", "without images");
////    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//    	tableView.addBasicItem("Example 2 - UITableView", "with images");
////    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//
//    	tableView.addBasicItem("Example 3 - UITableView", "just a few items");
////    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//    	tableView.addBasicItem("Example 4 - UITableView", "only one item");
//    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//
//    	tableView.addBasicItem("Example 5 - UITableViewActivity", "a sample activity");
////    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//    	tableView.addBasicItem("Example 6 - UITableViewActivity temp", "item with custom view");
////    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//    	tableView.addBasicItem("Example 7 - UIButton", "some floating buttons");
////    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//    	tableView.addBasicItem("Example 8 - Clear List", "this button will clear the list");
//    	tableView.addSegmentations(R.layout.default_blank_list_segmentation);
//
//    	tableView.setClickListener(this);
//    	tableView.commit();
		
		
	}

	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see com.alstudio.ui.base.BaseActivity#initData()
	 */
	@Override
	protected void initData() {
		// TODO Auto-generated method stub

	}
	
	
	//图片处理
	String[] imageUrls;

	
	class ItemAdapter extends BaseAdapter {

		private class ViewHolder {
			public TextView text;
			public ImageView image;
		}

		@Override
		public int getCount() {
			return imageUrls.length;
		}

		@Override
		public Object getItem(int position) {
			return position;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			View view = convertView;
			final ViewHolder holder;
			if (convertView == null) {
				view = getLayoutInflater().inflate(R.layout.item_list_image, parent, false);
				holder = new ViewHolder();
				holder.text = (TextView) view.findViewById(R.id.text);
				holder.image = (ImageView) view.findViewById(R.id.image);
				view.setTag(holder);
			} else {
				holder = (ViewHolder) view.getTag();
			}

			holder.text.setText("Item " + (position + 1));

			ALLocalEnv.getLocalEnv().getImageLoader().displayImage(imageUrls[position], holder.image, ALLocalEnv.getLocalEnv().getCycleImageDisplayOptions());

			return view;
		}
	}

	
	/* (non-Javadoc)
	 * @see com.alstudio.ui.base.BaseActivity#onPause()
	 */
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
//		ALLocalEnv.getLocalEnv().getImageLoader().clearMemoryCache();
	}

	/* (non-Javadoc)
	 * @see com.alstudio.view.tableview.ALTableView.ALTableViewClickListener#onClick(int)
	 */
	@Override
	public void onClick(int index) {
		// TODO Auto-generated method stub
		Toast.makeText(this, "点钟了"+index, Toast.LENGTH_SHORT).show();
	}
}
